package com.songlanyun.modules.exception;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.songlanyun.common.drive.IntegerEnum;

import java.util.Objects;

/**
 * 收藏错误异常枚举类
 */
public enum CollectException implements IntegerEnum<Integer> {

    COLLECT_EXITS(160000, "该商品已收藏"),
    COLLECT_SHOP_NOT_EXITS(160001, "收藏商品不存在"),
    ;


    private Integer code;

    private String msg;

    CollectException(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    @JsonCreator
    public static CollectException getByCode(int code) {
        for (CollectException value : CollectException.values()) {
            if (Objects.equals(code, value.getCode())) {
                return value;
            }
        }
        return null;
    }
}
